package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.PreventFireSpreadFacilities;
import com.ruoyi.system.mapper.PreventFireSpreadFacilitiesMapper;
import com.ruoyi.system.service.PreventFireSpreadFacilitiesService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 防止火灾蔓延设施(PreventFireSpreadFacilities)表服务实现类
 *
 * @author makejava
 * @since 2022-11-16 14:51:48
 */
@Service("preventFireSpreadFacilitiesService")
public class PreventFireSpreadFacilitiesServiceImpl implements PreventFireSpreadFacilitiesService {
    @Resource
    private PreventFireSpreadFacilitiesMapper preventFireSpreadFacilitiesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PreventFireSpreadFacilities queryById(Integer id) {
        return this.preventFireSpreadFacilitiesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param preventFireSpreadFacilities 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PreventFireSpreadFacilities> queryByPage(PreventFireSpreadFacilities preventFireSpreadFacilities, PageRequest pageRequest) {
        long total = this.preventFireSpreadFacilitiesDao.count(preventFireSpreadFacilities);
        return new PageImpl<>(this.preventFireSpreadFacilitiesDao.queryAllByLimit(preventFireSpreadFacilities, pageRequest), pageRequest, total);
    }

    @Override
    public List<PreventFireSpreadFacilities> selectList(PreventFireSpreadFacilities preventFireSpreadFacilities) {
        return preventFireSpreadFacilitiesDao.queryAll(preventFireSpreadFacilities);
    }

    /**
     * 新增数据
     *
     * @param preventFireSpreadFacilities 实例对象
     * @return 实例对象
     */
    @Override
    public PreventFireSpreadFacilities insert(PreventFireSpreadFacilities preventFireSpreadFacilities) {
        this.preventFireSpreadFacilitiesDao.insert(preventFireSpreadFacilities);
        return preventFireSpreadFacilities;
    }

    /**
     * 修改数据
     *
     * @param preventFireSpreadFacilities 实例对象
     * @return 实例对象
     */
    @Override
    public PreventFireSpreadFacilities update(PreventFireSpreadFacilities preventFireSpreadFacilities) {
        this.preventFireSpreadFacilitiesDao.update(preventFireSpreadFacilities);
        return this.queryById(preventFireSpreadFacilities.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.preventFireSpreadFacilitiesDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<PreventFireSpreadFacilities> preventFireSpreadFacilitiess, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(preventFireSpreadFacilitiess) || preventFireSpreadFacilitiess.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        preventFireSpreadFacilitiesDao.insertBatch(preventFireSpreadFacilitiess);
        return "成功";
    }
}
